import Vue from "vue";
import Router from "vue-router";
import Index from "@v/Index";
import Login from "@v/Login";
import sysMenu from "@v/sysMenu/Index";
import User from "@v/sysUser/Index";
import Role from "@v/sysRole/Index";
import Generator from "@v/generator/Index";
import sysInterface from "@v/sysInterface/Index";
import Dashboard from "@v/dashboard/Index";
import WxUser from "@v/wxUser/Index";
import apiDocs from "@v/apiDocs/Index";
import Icon from "@v/icon/Index";
import payTest from "@v/payTest/Index";

Vue.use(Router);

const router = new Router({
  routes: [
    {
      path: "/index",
      name: "首页",
      redirect: "/dashboard",
      component: Index,
      children: [
        {
          path: "/dashboard",
          name: "系统监控",
          component: Dashboard
        },
        {
          path: "/menu",
          name: "菜单管理",
          component: sysMenu
        },
        {
          path: "/user",
          name: "用户管理",
          component: User
        },
        {
          path: "/role",
          name: "角色管理",
          component: Role
        },
        {
          path: "/interface",
          name: "接口管理",
          component: sysInterface
        },
        {
          path: "/generator",
          name: "代码生成器",
          component: Generator
        },
        {
          path: "/icon",
          name: "图标库",
          component: Icon
        },
        {
          path: "/wxUser",
          name: "微信用户管理",
          component: WxUser
        },
        {
          path: "/apiDocs",
          name: "在线文档",
          component: apiDocs
        },
        {
          path: "/aliPay",
          name: "支付宝支付测试",
          component: payTest
        }
      ]
    },
    {
      path: "/**",
      name: "登录",
      component: Login
    }
  ]
});

//全局路由拦截
// router.beforeEach((to, from, next) => {
//   sessionStorage.setItem("currentUrl", to.path); //保存当前路径标识
//   sessionStorage.setItem("fromUrl", from.path); //保存当前路径标识

//   if (to.meta.requireAuth) {
//     // 判断该路由是否需要登录权限
//     if (sessionStorage.getItem("token")) {
//       //获取当前的token是否存在
//       next();
//     } else {
//       next({
//         path: "/Login",
//         query: { redirect: to.fullPath } // 将跳转的路由path作为参数，登录成功后跳转到该路由
//       });
//     }
//   } else {
//     next();
//   }
// });

export default router;
